package authuserbc

// 前端 https(明文)  + 后端 bcrypt 加密存储
import (
	"gitee.com/tgodfather/utility/auth"
	"golang.org/x/crypto/bcrypt"
)

// save   	username	-  用户名
//			savePassword = bcrypt(realPassword)

// check	校验处理
//
//	bcrypt.match(savePassword, inPassword)
type UserStore struct {
	storeUsername string
	storePassword string
}

func (s *UserStore) Username() string {
	return s.storeUsername
}
func (s *UserStore) Password() string {
	return s.storePassword
}

func (s *UserStore) Verify(v auth.Validator) (rc bool, err error) {

	rc = false
	err = bcrypt.CompareHashAndPassword([]byte(s.storePassword), []byte(v.VPassword()))
	if err == nil {
		rc = true
	}
	return rc, err
}

func NewUserStore(Username, Password string, opt ...auth.StoreOption) auth.AuthStore {

	sUsername := Username
	sPassword := Password
	// opts := auth.NewStoreOptions(opt...)

	ps := &UserStore{
		storeUsername: sUsername,
		storePassword: sPassword,
	}
	return ps
}
